﻿@model ListViewModel<CommonSearchValues2, IQueryable<Recuper>>
@{ var tm = new WebUI.Models.Recuper();
   var qsmssubjs = (ViewBag.SmsSubjects as IEnumerable<QizSmsSubject>).ToList();
}
<div class="toolbox">
    <div class="catalog-title">
        @("True".Equals(Request["IsContain"], StringComparison.CurrentCultureIgnoreCase) ? "浏览随访对象" : "添加随访对象")
        &nbsp;&nbsp; <a href="javascript:void(0)" onclick="$('#searchpan').toggle();">[切换高级查询...]</a>
    </div>
    @using (Ajax.BeginForm("SubjectRecuperList", new { IsContain = Request["IsContain"], IsView = false, SubjectID = Model.Tag.V1 }, new AjaxOptions { HttpMethod = "Post", LoadingElementId = "OnLoadingSpan", UpdateTargetId = "recuperlist", OnFailure = "OnSiteError" }))
    {
        <div class="small-input">
            @Html.HiddenFor(m => Model.Tag.V1)
            @Html.HiddenFor(m => Model.PageSize)
            <input type="hidden" name="PageIdx" id="qspidx" value="0" />
            <table class="width noborder inlinelabels-5" style="background-color: #f8f8f8">
                <tr>
                    <td valign="top">
                        <label>姓名：</label> @Html.EditorFor(m => m.SearchFrom.V1)<br />
                        <label>主管医生：</label>
                        @Html.DropDownListFor(m => m.SearchFrom.V11, new SelectList(SiteUser.Department.aspnet_Users.Select(v => v.UserName).ToArray(), Model.SearchFrom.V11), "全部")&nbsp;&nbsp;&nbsp;
                    </td>
                    <td valign="top">
                        <label>性别：</label> @Html.DropDownListFor(m => m.SearchFrom.V2, new SelectList("男,女".Split(','), Model.SearchFrom.V2), "", null)<br />
                        @if (bool.Parse(Request["IsContain"]))
                        {
                            <label>短信随访：</label>
                            @Html.DropDownListFor(m => m.SearchFrom.V12, new SelectList(ViewBag.SmsSubjects, "ID", "Title", Model.SearchFrom.V12), "全部")                            
                        }
                    </td>
                    <td valign="top">
                        <label>手机号码：</label> @Html.EditorFor(m => m.SearchFrom.V4)<br />                        
                    </td>
                    <td style="vertical-align: top">
                        @Helpers.SubmitButton("查询", "qssubmit")
                    </td>
                </tr>
                <tr>
                    <td valign="top" colspan="4">
                        <label>随访类型：</label>
                        @Html.EditorFor(m => m.SearchFrom.V6)
                    </td>
                </tr>                
            </table>
            <table id="searchpan" class="width noborder inlinelabels-5" style="background-color: #f8f8f8;display: none;">
                <tr>
                    <td valign="top">
                        <span class="big-input">
                            <label>出院诊断：</label>
                            @Html.EditorFor(m => m.SearchFrom.V8)<br />
                            <label>手术名称：</label>
                            @Html.EditorFor(m => m.SearchFrom.V10)</span>
                        <br />
                        <label>病案号：</label>
                        @Html.EditorFor(m => m.SearchFrom.V3)至 @Html.EditorFor(m => m.SearchTo.V3)
                    </td>
                    <td align="left" valign="top">
                        <label>出生日期：</label>
                        @Html.EditorFor(m => m.SearchFrom.V5, "DateTimeStr")至 @Html.EditorFor(m => m.SearchTo.V5, "DateTimeStr")<br />
                        <label>入院时间：</label>
                        @Html.EditorFor(m => m.SearchFrom.V7, "DateTimeStr")至 @Html.EditorFor(m => m.SearchTo.V7, "DateTimeStr")<br />
                        <label>出院时间：</label>
                        @Html.EditorFor(m => m.SearchFrom.V9, "DateTimeStr")至 @Html.EditorFor(m => m.SearchTo.V9, "DateTimeStr")
                    </td>
                </tr>
            </table>
            <div class="inlinelabels-5">
                排序：
                @{
                //诡异debug，html.textboxfor( model.sortorder或m.sortorder怎么也不对，但dispfor 或直接显示m.sortorder 就是对的
                //弄个变量试试也不行            //还是不行貌似html.textbox之类的有问题，靠用input就好了
                string sortfields = !string.IsNullOrEmpty(Request["IsContain"]) && Convert.ToBoolean(Request["IsContain"])
                    ? "出院时间,参加日期,姓名,年龄" : "出院时间,姓名,年龄";
                }
                <input type="hidden" value="@Model.SortOrder" name="SortOrder" id="SortOrder" />
                @*@Html.Hidden("SortOrder",  Model.SortOrder)*@
                @Html.EditorFor(m => m.SortBy, "SelButtonsField", new { Selects = new SelectList(sortfields.Split(','), Model.SortBy) })
            </div>
        </div>
    }
    </div>
<script type="text/javascript">
    function checkAll(e, itemName) {
        var aa = document.getElementsByName(itemName);    //获取全选复选框
        for (var i = 0; i < aa.length; i++) {
            aa[i].checked = e.checked;    //改变所有复选框的状态为全选复选框的状态
        }
    }
    function checkItem(e, allName) {
        var all = document.getElementsByName(allName)[0];    //获取全选复选框
        if (!e.checked) {
            //没被选中全选复选框置为false;
            all.checked = false;
        } else {
            //选中，遍历数组
            var aa = document.getElementsByName(e.name);
            for (var i = 0; i < aa.length; i++)
                //只要数组中有一个没有选中返回。假如所有的都是选中状态就将全选复选框选中;
                if (!aa[i].checked) return;
            all.checked = true;
        }
    }

</script>
<style type="text/css">
    #btn_advanced
    {
        font-size: 12px;
        padding: 3px;
        color: blue;
        text-decoration: underline;
    }

        #btn_advanced:hover
        {
            background: none;
            text-decoration: none;
        }
</style>
@using (Ajax.BeginForm("SubjectRecuperListEdit", new { IsView = false, SubjectID = Model.Tag.V1 }, new AjaxOptions { HttpMethod = "Post", LoadingElementId = "OnLoadingSpan", UpdateTargetId = "", OnSuccess = "alert('保存完成')", OnFailure = "OnSiteError" }))
{
    @Html.HiddenFor(m => Model.Tag.V1)
    <table class="width">
        <col style="white-space:nowrap" />
        <tr>
            <th>
                @Html.LabelFor(model => tm.User.UserName)
            </th>
            <th>
                @Html.LabelFor(model => tm.User.Gender)
            </th>
            <th>
                @Html.LabelFor(model => tm.SuiFangLeiXing)
            </th>
            <th>
                @Html.Label("主管医生")
            </th>
            <th>
                @Html.Label("年龄")
            </th>
            <th>
                @Html.LabelFor(model => tm.BingAnHao)
            </th>
            <th>
                @Html.LabelFor(model => tm.User.MobileAlias)
            </th>
            <th>
                @Html.Label("参加日期")
            </th>
            <th>
                @Html.LabelFor(model => tm.EnHospDay)
            </th>
            <th>
                @Html.LabelFor(model => tm.DeHospDay)
            </th>
            <th>
                <input type="checkbox" onclick="checkAll(this, 'SubjSelection')" name="allSelection" />常规随访
            </th>
            <th>
                短信随访
            </th>
        </tr>
        @{int dColor = 0;}
        @foreach (var item in Model.Data)
        {
            <tr class="tr-backColor@(dColor++ % 2)">
                <td>
                    @Ajax.ActionLink(item.User.UserName, "RecuperEdit", new { ID = item.UserID, _t = DateTime.Now.Ticks, _ReadOnly = true }, new AjaxOptions() { LoadingElementId = "OnLoadingSpan", UpdateTargetId = "dialogbox", OnComplete = "showDialog('患者信息');", HttpMethod = "Get", InsertionMode = InsertionMode.Replace, OnFailure = "OnSiteError" })
                    @*@Html.DisplayFor(model => item.User.UserName)*@
                </td>
                <td>
                    @Html.DisplayFor(model => item.User.Gender)
                </td>
                <td>
                    @Html.DisplayFor(model => item.SuiFangLeiXing)
                </td>
                <td>
                    @Html.DisplayFor(model => item.Doctor.UserName)
                </td>
                <td>
                    @Helpers.GetAge(item.User.BirthDay)
                </td>
                <td>
                    @Html.DisplayFor(model => item.BingAnHao)
                </td>
                <td>
                    @Html.DisplayFor(model => item.User.MobileAlias)
                </td>
                <td>
                    @{
            var sf = item.QizSubjectObjForDoctors.FirstOrDefault(v => v.QizSubjectID == Model.Tag.V1);
            if (null != sf)
            {
                        @Helpers.DateTimeString(sf.Timemark)
            }
                    }
                </td>
                <td>
                    @Html.DisplayFor(model => item.EnHospDay)
                </td>
                <td>
                    @if (item.DeHospDay != DateTime.MinValue)
                    {
                        @Html.DisplayFor(model => item.DeHospDay)
                    }
                </td>
                <td>
                    @Html.Hidden("RecuperIDs", item.RecuperID)
                    <input type="checkbox" name="SubjSelection" onclick="checkItem(this, 'allSelection')" value="@(item.RecuperID)" id="@(item.RecuperID.ToString())" 
                    @(item.QizSubjectObjForDoctors.Any(v => v.QizSubjectID == Model.Tag.V1 && v.Doctor.UserId == SiteUser.UserId) ? "checked='checked'" : string.Empty) />
                    <label for="@(item.RecuperID)">
                        是否参与</label>
                </td>
                <td>
                    @if (qsmssubjs.Count == 0)
                    {
                        <span class="error">无短信随访将被忽略</span>
                    }
                    <span style="display:@(qsmssubjs.Count == 0 ? "none" : "block")">
                        @Html.DropDownList("SmsSubjSelection", new SelectList(ViewBag.SmsSubjects, "ID", "Title", item.QizSubjectObjForDoctors.Where(v => v.QizSubjectID == Model.Tag.V1 && (v.DoctorID == SiteUser.UserId)).Select(v => v.QizSmsSubjectID).FirstOrDefault()))
                    </span>
                </td>
            </tr>
        }
    </table>
    @Helpers.SubmitButton("保存", "qssubmit")
}
<table class="width noborder">
    <tr>
        <td>
            @Html.Partial("Pagger", new PaggerViewModel { Act = "SubjectRecuperListEdit", PageIdx = Model.PageIdx, PageCount = Model.PageCount, ItemCount = Model.ItemCount })
        </td>
        <td align="right">
            @using (Html.BeginForm("SubjectRecuperListExport", null, new { IsContain = Request["IsContain"], SubjectID = Model.Tag.V1 }, FormMethod.Post, new { target = "_blank", onsubmit = "alert('根据导出数据的多少，可能会有需要很长时间，导出过程请耐心等待...。');" }))
            {
                var currentFilter = new ListViewModel<CommonSearchValues, string>() { SearchFrom = Model.SearchFrom, SearchTo = Model.SearchTo };
                <span style="display: none;">
                    @Html.Hidden("CurrentFilterOfJson", System.Web.Helpers.Json.Encode(currentFilter))
                    <input type="submit" name="ExportType" value="exportdetail" id="exportdetail" />
                </span>
                <a href="#SubjectRecuperListExport" onclick="$('#exportdetail').click()">导出随访与患者信息</a>
            }
        </td>
    </tr>
</table>
@Html.Partial("TrHilighter")
@{
    var sflxs = "'" + string.Join("','", SiteUser.Department.DepartmentProfiles.Where(v => v.SettingKey.Equals("SuiFangLeiXing", StringComparison.OrdinalIgnoreCase)).Select(v => v.SettingValue).Distinct().ToArray()) + "'";    
}
<script type="text/javascript">
    $(function () {
        $("#SearchFrom_V6").select2({ maximumSelectionSize: 1, tags: [ @Html.Raw(sflxs)] });
    });
</script>
